package com.whfc.iot.mach.processor;

import com.whfc.common.util.JSONUtil;
import com.whfc.hdc.service.AppDeviceService;
import com.whfc.iot.mach.constant.MsgConst;
import com.whfc.iot.mach.entity.MachMsg0x0B;
import com.whfc.iot.mach.redis.MachCmdRedisDao;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 0x0B消息处理
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/7/17 9:17
 */
@Component
public class MachUpMsgProcessor0x0B implements MachUpMsgProcessor<MachMsg0x0B> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @DubboReference(interfaceClass = AppDeviceService.class, version = "1.0.0")
    private AppDeviceService commonDeviceService;

    @Autowired
    private MachCmdRedisDao machCmdRedisDao;

    @Override
    public void processMsg(MachMsg0x0B reqMsg) {

        String textMsg = JSONUtil.toString(reqMsg);
        Integer deviceId = reqMsg.getDeviceId();
        logger.info("处理0x0B数据:{}", textMsg);

        //处理报警信息
        try {

            //清除指令缓存
            machCmdRedisDao.delCmd(deviceId);

            //修改状态
            commonDeviceService.setDeviceCmdAck(deviceId, MsgConst.DOWNSTREAM_CMD_0x8B);
        } catch (Exception ex) {
            logger.error("", ex);
        }
    }
}
